package com.sarnath.sardoop.common.spring;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sarnath.sardoop.common.utils.PropertiesLoader;

/**
 * 作者 ：尹国春 功能 ：重载spring中PropertyPlaceholderConfigurer
 */
public class PropertyUtil extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {
	//固定位置系统配置文件
	private static String innerConfig="classpath:config.properties";
	private static String tomcatConfig="file:"+System.getProperties().get("catalina.home") + "/conf/config.properties";
	private static PropertiesLoader loader = new PropertiesLoader(innerConfig,tomcatConfig);
	//固定位置日志配置文件
	static{
		BasicConfigurator.configure();
		String innerLog4j="classpath:log4j.properties";
		String tomcatLog4j="file:"+System.getProperties().get("catalina.home") + "/conf/log4j.properties";
		Logger logger=LoggerFactory.getLogger(PropertyUtil.class);
		logger.info("tomcat log4j:{}",tomcatLog4j);
		PropertyConfigurator.configure(new PropertiesLoader(innerLog4j,tomcatLog4j).getProperties());
		System.setProperty("HADOOP_USER_NAME", "hadoop");
	}
	public Properties mergeProperties() throws IOException {
		return loader.getProperties();
	}

	public static String getProperty(String key) {
		return loader.getProperty(key);
	}
}
